<template>
  <div class="warp">
    <div class="header warp-continer">
      <div class="postion">
        <i class="iconfont icon-weizhi1 dw"></i>
        <h4 class="title" @click="SelectAddress">{{ addressinfo }}</h4>
        <i class="iconfont icon-tixing1 tips"></i>
      </div>
      <div class="search">
        <i class="iconfont icon-fangdajing fdj"></i>
        <input type="text" @focus="Search" placeholder="山姆会员商店优惠商品" />
      </div>
      <div class="banner">
        <img src="../assets/banner.jpg" />
      </div>
      <nav class="nav">
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
        <a href="#" class="item">
          <img src="../assets/超市.png" />
          <span>超市便利</span>
        </a>
      </nav>
    </div>
    <div class="splie"></div>
    <!--附近店铺-->
    <div class="shop warp-continer">
      <h4 class="head-title">附近店铺</h4>
      <div
        class="item"
        @click="ToShop(item.id)"
        v-for="(item, index) in shopList"
        :key="index"
      >
        <div class="logo">
          <img :src="item.img" />
        </div>
        <div class="info">
          <h5 class="title">{{ item.name }}</h5>
          <p class="sale">
            <span>月售{{ item.sale }}万+</span
            ><span>起送¥{{ item.startprice }}</span
            ><span>基础运费¥{{ item.baseprice }}</span>
          </p>
          <p class="vip">{{ item.yhtext }}</p>
        </div>
      </div>
    </div>
    <docker></docker>
  </div>
</template>

<script>
import { get, post } from "../utils/requerst";
import Docker from "../components/Docker.vue";

export default {
  name: "Home",
  components: { Docker },
  data() {
    return {
      addressinfo: "请选择收货地址信息",
      shopList: [],
    };
  },
  created() {
    this.GetShopList();
    let addressId = this.$route.query.addressId;

    let addressList = this.$store.state.address.AddressList;
    if (addressList.length > 0) {
      if (addressId > 0) {
        var index = addressList.findIndex((item, index) => {
          return item.id == addressId;
        });
        if (index > -1)
          this.addressinfo =
            addressList[index].city +
            addressList[index].area +
            addressList[index].house;
      } else {
        this.addressinfo =
          addressList[0].city + addressList[0].area + addressList[0].house;
      }
    }
  },
  methods: {
    async GetShopList() {
      let { status, message, data } = await get("/api/shop/getlist");
      console.log(status);
      if (status) {
        this.shopList = data;
        
      } else {
        alert(message);
      }
    },
    Search() {
      this.$router.push({ name: "Search" });
    },
    //选择收货地址
    SelectAddress() {
      this.$router.push({
        path: "/Address",
        query: {
          from: "home",
        },
      });
    },
    ToShop(id) {
      this.$router.push({
        path: "/Shop",
        query: {
          shopId: id,
        },
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.warp-continer {
  padding: 0 18px;
}
.warp {
  .postion {
    padding: 16px 0px;

    display: flex;
    font-family: PingFangSC-Regular;
    justify-content: space-between;
    font-size: 16px;
    color: #333333;
    i {
      font-size: 18px;
    }
    .dw {
      margin-right: 8.5px;
    }
    h4 {
      flex: 1;
      word-wrap: break-word;
    }
    .tips {
      margin-left: 8.5px;
      font-size: 20px;
    }
  }
  .search {
    position: relative;
    .fdj {
      position: absolute;
      left: 10px;
      top: 8px;
    }
    input {
      padding-left: 38px;
      width: 100%;
      height: 32px;
      border: none;
      outline: none;
      background: #f5f5f5;

      border-radius: 16px;
      font-family: PingFangSC-Regular;
      font-size: 14px;
      color: #b7b7b7;
      line-height: 16px;
    }
  }
  .banner {
    margin-top: 12px;
    width: 100%;
    height: 86px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .nav {
    display: flex;

    flex-wrap: wrap;
    padding-bottom: 16px;

    .item {
      text-align: center;
      align-items: center;

      margin-top: 16px;
      display: flex;
      flex: 20%;
      flex-direction: column;
      img {
        width: 40px;
        height: 40px;
      }
      span {
        margin-top: 6px;
        font-family: PingFangSC-Regular;
        font-size: 12px;
        color: #333333;
        text-align: center;
      }
    }
  }
  .splie {
    width: 100%;
    height: 10px;
    background: #f1f1f1;
  }
  //附近店铺
  .shop {
    .head-title {
      font-family: PingFangSC-Medium;
      font-size: 18px;
      color: #333333;
      margin-top: 16px;
      margin-bottom: 14px;
      font-weight: bold;
    }
    .item {
      display: flex;
      .logo {
        width: 56px;
        height: 56px;
        margin-right: 16px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .info {
        flex: 1;
        padding-bottom: 15px;
        border-bottom: 1px solid #f1f1f1;
        .title {
          font-family: PingFangSC-Regular;
          font-size: 16px;
          color: #333333;
        }
        .sale {
          span {
            margin-right: 16px;
          }
          margin: 8px 0px;
        }
        .vip {
          font-family: PingFangSC-Regular;
          font-size: 13px;
          color: #e93b3b;
        }
      }
    }
    .item:nth-child(n + 1) {
      margin-top: 12px;
    }
  }
}
</style>
